Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
JS cannot read proprieties of null "innerHTML" on onload call

I have a function that will display content of item prices which can have their order changed from ascending to descending from the click of a button as well as the buttons innerHTML being changed to display text showing what order they are being displayed in. The onload function is called at the top of my HTML code. There is a check inside my function to see in innerHTML of the button (so it changes to the opposite value each time it is clicked) but when i call the function on onload it appears in console as

'Cannot read properties of null (reading 'innerHTML') at ....... at HTMLScriptElement.onload'

JS function:

function myFunc() {
    var elem = document.getElementById("selectionButton")
    if (elem.innerHTML=="descending") { elem.innerHTML = "ascending "}
    else { elem.innerHTML = "descending"}

Onload:

<script src="script.js" onload="myFunc()" ></script>

Buttons:

<button onclick="myFunc()" id="selectionButton" >Ascending</button>
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda